package com.gjzhao.fmmall.service.impl;

import com.gjzhao.fmmall.entity.Orders;
import com.gjzhao.fmmall.service.ApiOrderService;
import com.gjzhao.fmmall.vo.RespResultVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * @Description: ApiOrderServiceImpl
 * @Author: gjzhao
 * @Date Created in 2022-02-08 9:05 下午
 */
@Service
public class ApiOrderServiceImpl implements ApiOrderService {

    private Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private RestTemplate restTemplate;


    /**
     * 添加订单
     *
     * @param cartIds
     * @param order
     * @return
     */
    @Override
    public RespResultVO addOrder(String cartIds, Orders order) {


        logger.info("-----使用rest方式调用服务:----");
        RespResultVO respResultVO = restTemplate.postForObject("http://order-add/orders/add?cartIds=" + cartIds, order, RespResultVO.class);
        logger.info("-----使用rest方式调用结果:{}----", respResultVO);
        return respResultVO;
    }

    /**
     * 获取订单信息
     *
     * @param orderId
     * @return
     */
    @Override
    public RespResultVO getOrder(String orderId) {
        logger.info("-----使用rest方式调用服务----");
        RespResultVO resultVO = restTemplate.getForObject("http://order-add/orders/getOrder?orderId=" + orderId, RespResultVO.class);
        logger.info("-----使用rest方式调用结果:{}----", resultVO);
        return RespResultVO.success(resultVO);
    }

}
